﻿using Client;
using Shared.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StationClient.Dialog
{
    public partial class DialogNode : Form
    {
        STATION _sta = null;
        List<NODE> _listNode = null;
        NODE _nodeWhere = null;
        public DialogNode(NODE where,STATION sta)
        {
            _sta = sta;
            _nodeWhere = where;
            InitializeComponent();
        }

        private void DialogNode_Load(object sender, EventArgs e)
        {
            if(_nodeWhere==null || _sta == null)//判断参数是否错误
            {
                MessageBox.Show("传入参数为空");
                this.Close();
            }

            this.listViewNode.BeginUpdate();//开始更新结构

            var nodeRes = MethodWcf.SelectNodeClient(_nodeWhere);//查询工序结果
            if (nodeRes.result)
            {
                _listNode = nodeRes.value;
                for (int i = 0; i < _listNode.Count; i++)
                {
                    NODE node = _listNode[i];

                    ListViewItem item = new ListViewItem();
                    item.Text = node.ID.ToString();
                    item.ImageIndex = 1;
                    item.SubItems.Add(node.NAME);
                    item.SubItems.Add(node.CONTEXT);
                    item.SubItems.Add(node.LAST_ID.ToString());
                    item.SubItems.Add(node.NEXT_ID.ToString());
                    item.SubItems.Add(node.ERROR_ID.ToString());
                    item.SubItems.Add(node.FLAG.ToString());
                    this.listViewNode.Items.Add(item);
                }
            }
            this.listViewNode.EndUpdate();
        }

        private void listViewNode_MouseClick(object sender, MouseEventArgs e)
        {
            var selected = this.listViewNode.SelectedItems;

            if (this._listNode.Count >= 1 && selected.Count == 1)//ITEM的数量大于1
            {
                _sta.NODE_ID = long.Parse(selected[0].Text);
            }
            this.Close();
        }
    }
}
